package com.baichang.taoshunda.dao.impl;

import org.springframework.stereotype.Repository;

import com.baichang.framework.dao.impl.BaseDaoImpl;
import com.baichang.taoshunda.dao.UserAccountDao;
import com.baichang.taoshunda.entity.UserAccount;

import java.util.List;
import java.util.Map;

@Repository
public class UserAccountDaoImpl extends BaseDaoImpl<UserAccount> implements UserAccountDao {
    /**
     * 查询生活服务的账号
     *
     * @param type   分类
     * @param userId 用户编号
     * @return
     */
    @Override
    public List<Map<String, Object>> getUserAccount(Integer type, int userId) {
        String sql = "SELECT urh.id, urh.account, urh.item_id, urh.recharge_type, urh.amount , urh.created, urh.payment_unit, urh.order_number, ua.type AS accountType FROM t_user_recharge_history urh LEFT JOIN t_user_account ua ON ua.user_account = urh.account WHERE urh.user_id = ? AND urh.recharge_type = '水电煤充值' AND urh.`status` = 1 GROUP BY urh.account ORDER BY id DESC";
        return queryForMapList(sql, userId);
    }

    @Override
    public int getUserAccountByAccount(int userId, String rechargeAccount) {
        String sql = "SELECT COUNT(0) FROM `t_user_account` WHERE `user_id` = ? AND `user_account`=?";
        return queryForInt(sql, userId, rechargeAccount);
    }
}